package team.niit.util;

/**
 * @Author: HAPPY
 * @Project_name: student_select_course
 * @Package_name: team.niit.util
 * @Date: 2021/12/11 15:14
 * @Description:
 */
public class NoUtil {
    /**
     * 获取在一天中的索引
     * @param no 字符串
     * @return 索引值
     */
    public static int getInDayNo(String no) {
        switch (no) {
            case "1-2":
                return 0;
            case "3-4":
                return 1;
            case "5-6":
                return 2;
            case "7-8":
                return 3;
            case "9-10":
                return 4;
        }
        return 0;
    }

    /**
     * 将汉字日期字符串转为对应的索引值
     * 如： 星期一 1-2 转换后为 0
     * @param time 要转换的日期字符串
     * @return 转换后的日期索引
     */
    public static int getNo(String time) {
        int dayNo = 0;
        int inDayNo = 0;
        int res;
        if (time != null && time.length() > 3) {
            switch (time.substring(0, 3)) {
                case "星期一":
                    dayNo = 1;
                    break;
                case "星期二":
                    dayNo = 2;
                    break;
                case "星期三":
                    dayNo = 3;
                    break;
                case "星期四":
                    dayNo = 4;
                    break;
                case "星期五":
                    dayNo = 5;
                    break;
                case "星期六":
                    dayNo = 6;
                    break;
                case "星期日":
                    dayNo = 7;
                    break;
            }
            inDayNo = getInDayNo(time.substring(4));

            res = (dayNo - 1) * 5 + inDayNo;
        } else {
            res = 0;
        }

        return res;
    }
}
